package com.servlet.user;

import com.pojo.Yuyue;
import com.service.user.UserService;
import com.service.user.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class AppointServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String Ac = req.getParameter("ac");
        String ke = req.getParameter("ke");
        String date = req.getParameter("date");
        UserService userService = new UserServiceImpl();
        int n = userService.apo(Ac,ke,date);
        Yuyue y = new Yuyue();
        y.setAc(Ac);
        y.setKe(ke);
        y.setDate(date);
        if(n==1){
            HttpSession session=req.getSession();//预约成功 将预约信息存入session
            session.setAttribute("apoInfo", y);
            resp.sendRedirect("success.jsp");
        }else{
            req.setAttribute("error","预约信息有误！");
            req.getRequestDispatcher("main.jsp").forward(req,resp);
        }
    }
}
